home *** CD-ROM | disk | FTP | other *** search
/ Winzipper / Winzipper_ISO.iso / programming / oracle7 7.2 / DB / UTIL72 / DBMSDEFR.SQL < prev    next >
Encoding:
Text File  |  1995-05-09  |  36.7 KB  |  899 lines

  1. rem 
  2. rem $Header: dbmsdefr.sql 7020200.1 95/02/15 18:31:54 cli Generic<base> $ 
  3. rem 
  4. rem 
  5. Rem  Copyright (c) 1993 by Oracle Corporation 
  6. Rem  Copyright (c) 1992,1993 by Oracle Corporation
  7. Rem  ***** Oracle Propriatary                                           *****
  8. Rem  ***** This file contains the embodyment of propriatary technology. *****
  9. Rem  ***** It is for the sole use of Oracle employees and Oracle        *****
  10. Rem  ***** customers who have executed non-disclousure agreements.      *****
  11. Rem  ***** The contents of this file may not be disclosed to persons    *****
  12. Rem  ***** or organization who have not executed a non-disclousure      *****
  13. Rem  ***** agreement.                                                   *****
  14. Rem    NAME
  15. Rem      dbmsdefr.sql - replicated deferred remote procedure calls
  16. Rem    DESCRIPTION
  17. Rem      The external interfaces and bodies of two replication packages are 
  18. Rem      also included, as are some sequences used by the packages.
  19. Rem      All objects  are created in the schema 'SYS'.
  20. Rem       Packages
  21. Rem         dbms_defer
  22. Rem         dbms_defer_query
  23. Rem         dbms_defer_sys
  24. Rem 
  25. Rem    NOTES
  26. Rem      The algorithms used here were originally concieved by Sandeep
  27. Rem         Jain, and are described in a forthcomming memo by Sandeep Jain
  28. Rem      and Dean Daniels Titled "A Method for Defering Remote Procedure Calls
  29. Rem      Utilizing a Relational Database System.
  30. Rem
  31. Rem      The structures implemented by this package should probably be a
  32. Rem      cluster.  The create table statements can be modified to include
  33. Rem      storage information as appropriate for a particular installation.
  34. Rem
  35. Rem    DEPENDENCIES
  36. Rem      These packages use calls from  the DBMS_SQL, DBMS_ASYNCRPC, and
  37. Rem      DBMS_DEFER_PACK packages
  38. Rem      
  39. Rem    USAGE
  40. Rem      This script is to be run by user connected as INTERNAL.
  41. Rem
  42. Rem    SECURITY
  43. Rem      Tables and sequences created by this script are kept private
  44. Rem      The dbms_defer package is granted to public, but it is reasonable to 
  45. Rem      restrict access
  46. Rem      to users creating replicated applications.  
  47. Rem      The dbms_defer_query package can be exeucted by users who need to 
  48. Rem      monitor deferred rpc queus, for example dba correcing conflicts.
  49. Rem      The dbms_defer_sys package is granted to DBAs (by default)
  50. Rem      The dbms_defer_internal_sys packages is 
  51. Rem      kept  private. 
  52. Rem      The dbms_defer_pack package is kept private, as is dbms_asyncrpc.
  53. Rem     
  54. Rem    COMPATIBILITY
  55. Rem    MODIFIED   (MM/DD/YY)
  56. Rem     jstamos    02/01/95 -  default batch_size to 0
  57. Rem     dsdaniel   01/23/95 -  merge changes from branch 1.1.710.17
  58. Rem     dsdaniel   01/17/95 -  eliminate grat to public
  59. Rem     hasun      12/21/94 -  merge changes from branch 1.1.710.14&15&16
  60. Rem     dsdaniel   11/17/94 -  merge changes from branch 1.1.710.13
  61. Rem     dsdaniel   12/05/94 -  eliminate def_trandest table
  62. Rem     boki       12/02/94 -  modified execute(), adding new argument
  63. Rem     hasun      11/17/94 -  add Exception NOREPOPTION for factoring
  64. Rem     dsdaniel   10/26/94 -  coverage, interface changes
  65. Rem     dsdaniel   10/13/94 -  merge changes from branch 1.1.710.11&12
  66. Rem     dsdaniel   09/12/94 -  comment in dbms_defer_query
  67. Rem     dsdaniel   07/11/94 -  dbms_sys_error upgrade
  68. Rem     adowning   06/14/94 -  merge latest revision from repint
  69. Rem     adowning   04/29/94 -  merge latest revisions from repint
  70. Rem     dsdaniel   03/29/94 -  error message change
  71. Rem     dsdaniel   02/17/94 -  repcat integration
  72. Rem     adowning   02/02/94 -  split file into public / private binary files
  73. Rem     dsdaniel   01/20/94 -  dbms_sys_error error range change
  74. Rem     rjenkins   01/13/94 -  giving RESET a default
  75. Rem     dsdaniel   12/27/93 -  dbms_sys_sql change
  76. Rem     rjenkins   12/22/93 -  oops
  77. Rem     rjenkins   12/17/93 -  creating job queue
  78. Rem     dsdaniel   11/02/93 -  dbms_sql.parse changes
  79. Rem     dsdaniel   10/28/93 -  deferred rpc dblink security
  80. Rem     dsdaniel   10/26/93 -  merge changes from branch 1.1.400.3
  81. Rem     dsdaniel   10/10/93 -  break out queue tables
  82. Rem     rjenkins   10/07/93 -  adding deferrcount
  83. Rem     dsdaniel   08/30/93 -  package for instalation by system
  84. Rem     dsdaniel   08/04/93 -  Creation by renaming dbmsrrpc.sql
  85. Rem     dsdaniel   05/17/93 -  upgrade to 7.0/7.1 version 
  86. Rem     dsdaniel   02/22/93 -  Creation 
  87. Rem   *******************************************************************
  88. Rem 
  89. Rem      
  90. Rem
  91.  
  92. REM ********************************************************************
  93. REM THIS PACKAGE MUST NOT BE MODIFIED BY THE CUSTOMER.  DOING SO
  94. REM COULD CAUSE INTERNAL ERRORS AND SECURITY VIOLATIONS IN THE
  95. REM RDBMS.  SPECIFICALLY, THE PSD* ROUTINES MUST NOT BE CALLED
  96. REM DIRECTLY BY ANY CLIENT AND MUST REMAIN PRIVATE TO THE PACKAGE BODY.
  97. REM ********************************************************************
  98.  
  99. CREATE OR REPLACE PACKAGE dbms_defer AS
  100.   -------------------
  101.   --  OVERVIEW
  102.   -- 
  103.   -- This package in the user interface to a replicated transactional 
  104.   -- deferred remote
  105.   -- procedre call facility.  Replicated applications use the calls 
  106.   -- in this interface
  107.   -- to queue procedure call for later transactional execution at remote nodes.
  108.   -- These routines are typically called from either after row triggers 
  109.   -- or application
  110.   -- specified update procedures.
  111.   ------------
  112.   --  SECURITY
  113.   --
  114.   -- By default, this package is granted to public, but it may be 
  115.   -- more appropriate to
  116.   -- restrict execution to users authorized to create replicated applications.
  117.   -------------
  118.   --  CONSTANTS
  119.   --
  120.   --     constants used in the arg_type column of the def$_args table
  121.   --     definitions cpopied from dtydef.h
  122.   --
  123.   arg_type_num      CONSTANT NUMBER := 2;  -- DTYNUM 
  124.   arg_type_char     CONSTANT NUMBER := 96; -- DTYAFC
  125.   arg_type_varchar2 CONSTANT NUMBER := 1;  -- DTYCHAR
  126.   arg_type_date     CONSTANT NUMBER := 12; -- DTYDAT
  127.   arg_type_rowid    CONSTANT NUMBER := 11; -- DTYRID
  128.   arg_type_raw      CONSTANT NUMBER := 23; -- DTYBIN
  129.   --     definition same as dbms_repcat_mas.repcat_status_normal
  130.   --     (don't want to require repcat to be loaded)
  131.   repcat_status_normal  CONSTANT NUMBER := 0.0;
  132.   --
  133.   ---------
  134.   --  TYPES
  135.   --
  136.   --    node list type used for the defer_txn call
  137.   --      representation is an array (table) indexed from 1 up to a NULL
  138.   --      entry or NO_DATA_FOUND
  139.   TYPE node_list_t IS TABLE OF  VARCHAR2(128) INDEX BY BINARY_INTEGER;
  140.   --
  141.   -----------------
  142.   --  EXCEPTIONS
  143.   --
  144.   --  Parameter type does not match actual type. 
  145.   bad_param_type EXCEPTION;
  146.   PRAGMA exception_init(bad_param_type, -23325);
  147.   bad_param_num NUMBER := -23325;
  148.  
  149.   --  The database is being quieced.
  150.   deferred_rpc_quiesce EXCEPTION;
  151.   PRAGMA exception_init(deferred_rpc_quiesce, -23326);
  152.   quiesce_num NUMBER := -23326;
  153.   quiesce_msg VARCHAR(76) := 'the system is being quiesced.';
  154.  
  155.   --  Generic errors that are not important enough for specific exceptions
  156.   --  string text will explain them further.  These are internal errors.
  157.   --  message varies.
  158.   dbms_defererror EXCEPTION;
  159.   PRAGMA exception_init(dbms_defererror, -23305);
  160.   deferror_num NUMBER := -23305;
  161.  
  162.   --  
  163.   --    dbms_defer package detects mal-formed call (e.g. argument count
  164.   --     miss-match).  Message varies.
  165.   malformedcall EXCEPTION;
  166.   PRAGMA  exception_init(malformedcall, -23304);  
  167.   malformed_num NUMBER := -23304;
  168.  
  169.   --   generic exceptions that (user-written) defered procedures 
  170.   --   can raise to indicate
  171.   --   that the remote update has failed because of data updates by concurrent 
  172.   --   transactions.  A deferror table record will be created by the deferred 
  173.   --    rpc executor
  174.   updateconflict  EXCEPTION;
  175.   PRAGMA  exception_init(updateconflict, -23303);
  176.   conflict_num NUMBER := -23303;
  177.   conflict_msg VARCHAR(76) := 'Remote update failed due to conflict.';
  178.  
  179.   --   generic exceptions that (user-written) defered procedures 
  180.   --   can raise to indicate 
  181.   --   that the remote update has failed because communications failures
  182.   --   so that a a deferror table record will not be created by the 
  183.   --   deferred rpc 
  184.   --   executor.
  185.   commfailure  EXCEPTION;
  186.   PRAGMA  exception_init(commfailure, -23302);
  187.   commfail_num NUMBER := -23302;
  188.   commfail_msg VARCHAR(76) := 
  189.                          'Remote update failed due to communication failure';
  190.  
  191.   --   mixed use repcat determined destinations and non-repca destinations
  192.   --   in one transaction 
  193.   mixeddest  EXCEPTION;
  194.   PRAGMA  exception_init(mixeddest, -23301);
  195.   mixeddest_num NUMBER := -23301;
  196.   mixeddest_msg VARCHAR(76) := 
  197.            'Destinations for transaction not consistently specified';
  198.  
  199.   --   parameter length exceed deferred rpc limits (2000 char/varchar2, 
  200.   --   255 raw) in one transaction 
  201.   parameterlength  EXCEPTION;
  202.   PRAGMA  exception_init(parameterlength, -23323);
  203.   paramlen_num NUMBER := -23323;
  204.   paramlen_msg VARCHAR(76) := 'parameter length exceeds deferred rpc limits';
  205.  
  206.   --   deferred rpc execution is diabled
  207.   executiondisabled  EXCEPTION;
  208.   PRAGMA  exception_init(executiondisabled, -23354);
  209.   executiondisabled_num NUMBER := -23354;
  210.   paramlen_msg VARCHAR(76) := 'parameter length exceeds deferred rpc limits';
  211.   ----------------------
  212.   --  PROCEDURES
  213.   --
  214.   PROCEDURE commit_work(commit_work_comment IN VARCHAR2);
  215.   --  Perform a transaction commmit after checking for well-formed 
  216.   --    defered RPCs.
  217.   --    Must be used instead of the commit work sql call for 
  218.   --    transactions defering RPCS.
  219.   --    Updates the comment_comment and commit_scn fields in 
  220.   --    the def$_txn table.
  221.   --  Input parameters:
  222.   --    commit_work_comment
  223.   --      Up to fifty characters to describe the transaction 
  224.   --        in the def$_txns
  225.   --        table and system two-phase commit tables (this latter 
  226.   --        once we figure out
  227.   --        how to get it in.)  Comment is truncated to fifty characters.
  228.   --  Exceptions
  229.   --    ORA-23304 (malformedcall) if there is an defer_rpc_arg 
  230.   --      call missing or defer_txn
  231.   --      was not called for this transaction.
  232.   --
  233.   --
  234.   --
  235.   --  Transaction and call deferrral procedures
  236.   --    A defered transaction consist of the following:
  237.   --      Call to dbms_defer.transaction (this is optional, the first call to 
  238.   --      dbms_defer.call will call transaction)
  239.   --      one or more complete calls, each of which consists of 
  240.   --        Call to dbms_defer.call
  241.   --           zero of more calls (depending on arg_count in 
  242.   --           dbms_defer.call) to dbms_defer.arg_*
  243.   --      commit or call to commit_work
  244.   -- 
  245.   --  DESTINATION SPECIFICATION
  246.   --  Destinations can be specified in seversal ways
  247.   --  A) All deferred procedures are in repcat and the default list is
  248.   --     NOT specified int the transcion call.
  249.   --  OR
  250.   --  B) destionation are specified without repcat using the following order 
  251.   --     of precidence
  252.   --   1) list specified in the nodes parameter to dbms_defer.call
  253.   --   2) list specified in the nodes parameter to dbms_defer.transaction
  254.   --   3) list specified in defdefaultdest table.]=
  255.   --   The mixeddest exeception is raised if an attempt to mix destinations modees
  256.   --   is detected.
  257.   --
  258.   PROCEDURE transaction;
  259.   PROCEDURE transaction(nodes      IN node_list_t);
  260.   --  Mark a transaciton as defered (as containing deferred RPCs )
  261.   --     This call is optional.  The first call to dbms_defer.call 
  262.   --     in a transaction will call
  263.   --     deftxn (with no arguments) if it has not been previously called.
  264.   --     Input parameters are optional, and if they are not 
  265.   --     specified the destination
  266.   --     list is taken from the system defaults stored in the 
  267.   --     def$_defaultdest table and
  268.   --     maintained by the dbms_defer_sys.add_default_node and 
  269.   --     dbms_defer_sys.delete_default_node calls
  270.   --  Input parameters:
  271.   --    nodes
  272.   --      Table containg a list of nodes (dblink) to propogate the 
  273.   --      deferred calls of the 
  274.   --        transaction to.  Indexed from 1 until a NULL entry is
  275.   --        found or NO_DATA_FOUND is raised.  
  276.   --        Case insensitive comparison
  277.   --        used for node lists.
  278.   --        Use of this parameter overrides distribution lists as 
  279.   --        specified in repcat.
  280.   --  Exceptions
  281.   --    ORA-23304 (malformedcall) if the previous transaction 
  282.   --      not correctly formed 
  283.   --      or terminated
  284.   --    ORA-23319 Parameter value is not appropriate
  285.   --    ORA-23352 Raised by dbms_defer.call if the node 
  286.   --              list contains duplicats
  287.   ----
  288.  
  289.   PROCEDURE call( schema_name  IN VARCHAR2,
  290.                   package_name IN VARCHAR2,
  291.                   proc_name    IN VARCHAR2,    
  292.                   arg_count    IN NATURAL);
  293.  
  294.   PROCEDURE call( schema_name  IN VARCHAR2,
  295.                   package_name IN VARCHAR2,
  296.                   proc_name    IN VARCHAR2,    
  297.                   arg_count    IN NATURAL,
  298.                   nodes        IN node_list_t);
  299.   --  Defer a remote procedure call.  Automatically call 
  300.   --    deftxn if this is the first
  301.   --    call call of a transaction.
  302.   --  Input parameters:
  303.   --    schema_name
  304.   --      Name of the schema containing the remote procedure.  For
  305.   --      compatibility with future compile-time checking only string
  306.   --      constants should be used.  
  307.   --    package_name
  308.   --      Name of the package containing the remote procedure.  For
  309.   --      compatibility with future compile-time checking only string
  310.   --      constants should be used.  
  311.   --    proc_name
  312.   --      Name of the remote procedure to call.  
  313.   --        For compatibility with
  314.   --        future syntatic integration
  315.   --        and compile-time checking only string constants should be used.
  316.   --    arg_count
  317.   --       Number of parameters to the procedure.  This must 
  318.   --       exactly match the number of
  319.   --       defrpcarg_* calls immediatly following the dbms_defer.call call.
  320.   --    nodes
  321.   --      Optional table containing a list of nodes to propogate the 
  322.   --      deferred call to.  
  323.   --        Indexed from 1 until a NULL entry is
  324.   --        found or NO_DATA_FOUND is raised.  
  325.   --        Case insensitive comparison
  326.   --        used for node lists.
  327.   --      If not specified, the destination list is determined by the
  328.   --      list passed to the transaction procedure, or the system defaults,
  329.   --      Use of this parameter in any deferreed call invalidate the use of
  330.   --      the use of repcat to determine distribution lists in any
  331.   --      calls for a transaction.
  332.   --  Exceptions  -- 
  333.   --  Exceptions
  334.   --    ORA-23304 (malformedcall) if the previous call not 
  335.   --      correctly formed (number of
  336.   --      defrpcarg_* call not matched to arg_count).
  337.   --    ORA-23319 Parameter value is not appropriate
  338.   --    ORA-23352  If the destination list (spedified by nodes or by a previous
  339.   --              dbms_defer.transaction call contains a duplicate.
  340.   ----
  341.  
  342.   PROCEDURE number_arg(arg IN nUMBER);
  343.   --  Queue a number parameter value for a defered call.
  344.   --  Input parameter:
  345.   --    arg 
  346.   --      The number value of the parameter to the call 
  347.   --        previously defered with a 
  348.   --        dbms_defer.call call.
  349.   --  Exceptions: none.
  350.   --------
  351.  
  352.   PROCEDURE date_arg(arg IN DATE);
  353.   --  Queue a date parameter value for a defered call.
  354.   --  Input parameter:
  355.   --    arg 
  356.   --      The date value of the parameter to the call previously 
  357.   --      defered with a 
  358.   --        dbms_defer.call call.
  359.   --  Exceptions: none.
  360.   --------
  361.     
  362.   PROCEDURE varchar2_arg(arg  IN VARCHAR2);
  363.   --  Queue a varchar2 parameter value for a defered call.
  364.   --  Input parameter:
  365.   --    arg 
  366.   --      The varchar2 value of the parameter to the call 
  367.   --        previously defered with a 
  368.   --        dbms_defer.call call. The length of arg is limited to 2000.
  369.   --  Exceptions: 
  370.   --    whatever error sql gives if arg exceeds 2000 characters.
  371.  
  372.   PROCEDURE char_arg(arg  IN CHAR);
  373.   --  Queue a char parameter value for a defered call.
  374.   --  Input parameter:
  375.   --    arg 
  376.   --      The char value of the parameter to the call previously 
  377.   --        defered with a 
  378.   --        dbms_defer.call call. The length of arg is limited to 2000.
  379.   --  Exceptions: 
  380.   --    whatever error sql gives if arg exceeds 2000 characters.
  381.  
  382.   ---------------------
  383.   -- The following calls will not be supported until dbms_sql 
  384.   -- supports rowid and raw arguments.
  385.   -- 
  386.   -- rowids can not be
  387.   -- used on different nodes.  It might be reasonable to use a
  388.   -- rid in a defered call 
  389.   -- to a local node, but be carefull
  390.   PROCEDURE rowid_arg(arg IN ROWID);
  391.   --  Queue a rowid parameter value for a defered call.
  392.   --  Input parameter:
  393.   --    arg 
  394.   --      The rowid value of the parameter to the call 
  395.   --        previously defered with a 
  396.   --        dbms_defer.call call.
  397.   --  Exceptions: 
  398.   --    dbms_deferError
  399.   --------
  400.  
  401.   -- The following calls will not be supported until dbms_sql 
  402.   -- supports 
  403.   -- 
  404.   PROCEDURE raw_arg(arg IN raw);
  405.   --  Queue a rowid parameter value for a defered call.
  406.   --  Input parameter:
  407.   --    arg 
  408.   --      The raw value of the parameter to the call 
  409.   --        previously defered with a 
  410.   --        dbms_defer.call call.
  411.   --  Exceptions: 
  412.   --    dbms_deferError
  413.   --------
  414.   --------
  415. END dbms_defer;
  416. /
  417. --  This package is not granted to public becasuse of a user can 
  418. --  potentially steal the rights of the user pushing the deferred rpcs.
  419. --- be careful who execute is granted to.
  420. --  The public synonym is 
  421. --  probably usefull
  422. DROP PUBLIC SYNONYM dbms_defer;
  423. CREATE PUBLIC SYNONYM dbms_defer FOR dbms_defer;
  424.  
  425. CREATE OR REPLACE PACKAGE dbms_defer_query AS
  426.   -------------------
  427.   --  OVERVIEW
  428.   -- 
  429.   -- This package permits querying the deferred RPC queu data that
  430.   -- is not exposed through views.
  431.   FUNCTION get_arg_type(callno           IN  NUMBER,
  432.                         deferred_tran_db IN  VARCHAR2,
  433.                         arg_no           IN  NUMBER,
  434.                         deferred_tran_id IN  VARCHAR2 DEFAULT NULL)
  435.     RETURN NUMBER;
  436.   -- Return type  of a deferred call parameter.
  437.   -- Input parameters
  438.   --  callno
  439.   --    call identifier from the defCall view
  440.   --  deferred_tran_db 
  441.   --    database deferring call from the defCall view
  442.   --  arg_no
  443.   --    postition of desired parameter  in calls argument list
  444.   --    parameter positions are 1..number of parameters in call
  445.   --  deferred_tran_id
  446.   --    optionally specify deferred transaciton id for indexed access.
  447.   --    used internally.
  448.   ----
  449.   --  Result
  450.   --    The type of the deferred rpc parameter.
  451.   ------
  452.   --  EXCEPTIONS
  453.   --    NO_DATA_FOUND desired parameter value not found in the deferred rpc
  454.   --    queue tables.
  455.   ------
  456.   FUNCTION get_number_arg(callno           IN  NUMBER,
  457.                           deferred_tran_db IN  VARCHAR2,
  458.                           arg_no           IN  NUMBER)
  459.     RETURN NUMBER;
  460.   -- Return a deferred call parameter.
  461.   -- Input parameters
  462.   --  callno
  463.   --    call identifier from the defCall view
  464.   --  deferred_tran_db 
  465.   --    database deferring call from the defCall view
  466.   --  arg_no
  467.   --    postition of desired parameter  in calls argument list
  468.   --    parameter positions are 1..number of parameters in call
  469.   ----
  470.   --  Result
  471.   --    The value of the parameter .
  472.   ------
  473.   --  EXCEPTIONS
  474.   --    NO_DATA_FOUND desired parameted value not found in the deferred rpc
  475.   --    queue tables.
  476.   --    WRONG_TYPE if the desired prameter is not a number.
  477.   -------
  478.   FUNCTION get_varchar2_arg(callno           IN  NUMBER,
  479.                             deferred_tran_db IN  VARCHAR2,
  480.                             arg_no           IN  NUMBER)
  481.     RETURN VARCHAR2;
  482.   -- Return  a deferred call parameter.
  483.   -- Input parameters
  484.   --  callno
  485.   --    call identifier from the defCall view
  486.   --  deferred_tran_db 
  487.   --    database deferring call from the defCall view
  488.   --  arg_no
  489.   --    postition of desired parameter  in calls argument list
  490.   --    parameter positions are 1..number of parameters in call
  491.   ----
  492.   --  Result
  493.   --    The value of the parameter .
  494.   ------
  495.   --  EXCEPTIONS
  496.   --    NO_DATA_FOUND desired parameted value not found in the deferred rpc
  497.   --    queue tables.
  498.   --    WRONG_TYPE if the desired prameter is not a VARCHAR2.
  499.   -------
  500.   FUNCTION get_char_arg(callno           IN  NUMBER,
  501.                         deferred_tran_db IN  VARCHAR2,
  502.                         arg_no           IN  NUMBER)
  503.     RETURN CHAR;
  504.   -- Return type  of a deferred call parameter.
  505.   -- Input parameters
  506.   --  callno
  507.   --    call identifier from the defCall view
  508.   --  deferred_tran_db 
  509.   --    database deferring call from the defCall view
  510.   --  arg_no
  511.   --    postition of desired parameter  in calls argument list
  512.   --    parameter positions are 1..number of parameters in call
  513.   ----
  514.   --  Result
  515.   --    The value of the parameter .
  516.   ------
  517.   --  EXCEPTIONS
  518.   --    NO_DATA_FOUND desired parameted value not found in the deferred rpc
  519.   --    queue tables.
  520.   --    WRONG_TYPE if the desired prameter is not a char.
  521.   -------
  522.   FUNCTION get_date_arg(callno           IN  NUMBER,
  523.                         deferred_tran_db IN  VARCHAR2,
  524.                         arg_no           IN  NUMBER)
  525.     RETURN DATE;
  526.   -- Return  a deferred call parameter.
  527.   -- Input parameters
  528.   --  callno
  529.   --    call identifier from the defCall view
  530.   --  deferred_tran_db 
  531.   --    database deferring call from the defCall view
  532.   --  arg_no
  533.   --    postition of desired parameter  in calls argument list
  534.   --    parameter positions are 1..number of parameters in call
  535.   ----
  536.   --  Result
  537.   --    The value of the parameter .
  538.   ------
  539.   --  EXCEPTIONS
  540.   --    NO_DATA_FOUND desired parameted value not found in the deferred rpc
  541.   --    queue tables.
  542.   --    WRONG_TYPE if the desired prameter is not a date.
  543.   -------
  544.   FUNCTION get_raw_arg(callno           IN  NUMBER,
  545.                         deferred_tran_db IN  VARCHAR2,
  546.                         arg_no           IN  NUMBER)
  547.     RETURN RAW;
  548.   -- Return  a deferred call parameter.
  549.   -- Input parameters
  550.   --  callno
  551.   --    call identifier from the defCall view
  552.   --  deferred_tran_db 
  553.   --    database deferring call from the defCall view
  554.   --  arg_no
  555.   --    postition of desired parameter  in calls argument list
  556.   --    parameter positions are 1..number of parameters in call
  557.   ----
  558.   --  Result
  559.   --    The value of the parameter .
  560.   ------
  561.   --  EXCEPTIONS
  562.   --    NO_DATA_FOUND desired parameted value not found in the deferred rpc
  563.   --    queue tables.
  564.   --    WRONG_TYPE if the desired prameter is not a raw.
  565.   -------
  566.   FUNCTION get_rowid_arg(callno           IN  NUMBER,
  567.                          deferred_tran_db IN  VARCHAR2,
  568.                          arg_no           IN  NUMBER)
  569.     RETURN ROWID;
  570.   -- Return  a deferred call parameter.
  571.   -- Input parameters
  572.   --  callno
  573.   --    call identifier from the defCall view
  574.   --  deferred_tran_db 
  575.   --    database deferring call from the defCall view
  576.   --  arg_no
  577.   --    postition of desired parameter  in calls argument list
  578.   --    parameter positions are 1..number of parameters in call
  579.   ----
  580.   --  Result
  581.   --    The value of the parameter .
  582.   ------
  583.   --  EXCEPTIONS
  584.   --    NO_DATA_FOUND desired parameted value not found in the deferred rpc
  585.   --    queue tables.
  586.   --    WRONG_TYPE if the desired prameter is not a rowid.
  587.   -------
  588. END dbms_defer_query;
  589. /
  590. DROP PUBLIC SYNONYM dbms_defer_query;
  591. CREATE PUBLIC SYNONYM dbms_defer_query FOR dbms_defer_query;
  592. GRANT EXECUTE on dbms_defer_query TO DBA;
  593.  
  594. CREATE OR REPLACE PACKAGE dbms_defer_sys AS
  595.   -------------------
  596.   --  OVERVIEW
  597.   -- 
  598.   -- This package is the system administrator  interface to a replicated 
  599.   -- transactional deferred remote
  600.   -- procedure call facility.  Administrators and replication 
  601.   -- deamons can execute
  602.   -- transactions queued for remote nodes using this facility 
  603.   -- and administrators
  604.   -- can control the nodes to which remote calls are destined.
  605.   ------------
  606.   --  SECURITY
  607.   --
  608.   -- By default, this package is owned by user SYS and 
  609.   -- execution should 
  610.   -- only to administrators and deamons that perform 
  611.   -- replciation adinistration and
  612.   -- execute defered transactions.  See the security considerations for 
  613.   -- the dbms_defer package for related considerations.
  614.   -------------
  615.   --  EXCEPTIONS
  616.   --
  617.   --  Parameter type does not match actual type. Message varies.
  618.   crt_err_err EXCEPTION;
  619.   PRAGMA exception_init(crt_err_err, -23324);
  620.   crt_err_num NUMBER := -23324;
  621.   crt_err_msg  VARCHAR(76) := 'Error creating deferror entry: ';
  622.  
  623.   --  Replication is not linked as an option
  624.   norepoption EXCEPTION;
  625.   PRAGMA exception_init(norepoption, -2094);   
  626.   norepoption_num NUMBER := -2094;
  627.  
  628.   -------------
  629.   --  CONSTANTS
  630.   --  size of long buffer used for packing parameters
  631.   parm_buffer_size CONSTANT NUMBER := 4096;
  632.   default_alert_name CONSTANT VARCHAR2(30) := 'ORA$DEFER_ALERT';
  633.   --  PROCEDURES
  634.  
  635.   -- manage default replication node lists
  636.  
  637.   PROCEDURE add_default_dest(dblink IN VARCHAR2);
  638.   --  Add a node to the default list for replication targets.
  639.   --  Input parameters
  640.   --    dblink
  641.   --      name of the node (dblink) to add tRo the default list.
  642.   --  Exceptions 
  643.   --    ORA-23352
  644.   --     dblink is already in the default list.
  645.   ----------
  646.  
  647.   PROCEDURE delete_default_dest(dblink IN VARCHAR2);
  648.   --  Delete a node from the default list for repliation targets
  649.   --  Input parameters
  650.   --    dblink
  651.   --      name of the node (dblink) to delete from the default list.
  652.   --      Operation is a no-op if dblink is not in the list.
  653.   --  Exceptions
  654.   --    none.
  655.   -----------------
  656.  
  657.   PROCEDURE execute(destination       IN VARCHAR2,
  658.                     stop_on_error     IN BOOLEAN := FALSE,
  659.                     transaction_count IN BINARY_INTEGER := 0,
  660.                     execution_seconds IN BINARY_INTEGER := 0,
  661.             execute_as_user   IN BOOLEAN := FALSE,
  662.                     delay_seconds     IN NATURAL := 0,
  663.                     batch_size        IN NATURAL := 0);
  664.  
  665.   --  Execute transactions queued for destination_node. stop_on_error 
  666.   --  determines whether processing of subsequent transaction continues
  667.   --  after an error is detected. 
  668.   --  deftrandest (and defcalldest if appropriate) entries 
  669.   --  for the successfully executed transactions are deleted and if
  670.   --  there are no other refreences, the defcall and deftran entries are deleted.
  671.   --
  672.   --  Input Parameters:
  673.   --    destination
  674.   --      node (dblink) at which to execute 
  675.   --      deferred transaction.  Case
  676.   --      insesitive comparisons used.
  677.   --    stop_on_error
  678.   --      If TRUE, execution of queued transactions will 
  679.   --      alway stop when an error is
  680.   --      encountered, leaving unattempted transaction in 
  681.   --      the queue.  If FALSE,
  682.   --      execution continues except when errors that appear 
  683.   --      to mean that node is 
  684.   --      unavailable are encountered, it which case execution 
  685.   --      always stops, leaving
  686.   --      unattempted transactions queued.
  687.   --    transaction_count
  688.   --      If positive, at most this many transactions will be executed.
  689.   --    executions_seconds
  690.   --      If positive, execution will stop after completions of the
  691.   --      last transaction after this many seconds of executions.
  692.   --    execute_as_user
  693.   --      IF TRUE the execution of deferred RPCs is authenticated at the 
  694.   --      remote system using the authentication context of the session user.  If 
  695.   --      FALSE the execution of deferred RPCs is authenticated at the remote system 
  696.   --      using the authentication contexts of the users that originally queued the 
  697.   --      deferred RPCs (indicated in the origin_user column of the deftran table). 
  698.   --    delay_seconds
  699.   --      If positive, the routine will sleep for this many seconds before
  700.   --      returning when it finds no deferrd RPCs queues for the destination
  701.   --      Non-zero values can redue execution overhead compared to calling
  702.   --      dbms_defer_sys.execute from a tight loop.
  703.   --    batch_size
  704.   --      The number of deferred rpc calls should be executed before 
  705.   --      commiting deferred transactions.  If batch_size is 0 a commit will
  706.   --      occur after each deferred transaction.  If batch_size is greater than
  707.   --      zero a commit will occrur when the total number of deferred calls
  708.   --      executed exceeds batch_size and a complete transaction has been
  709.   --      executed.
  710.   --
  711.   --  Exceptions
  712.   --    Raises the last exception encountered before execution 
  713.   --    stops because of 
  714.   --    an exception.
  715.   ----------------
  716.  
  717.   PROCEDURE execute_error(deferred_tran_id IN VARCHAR2,
  718.                           deferred_tran_db IN VARCHAR2,
  719.                           destination      IN VARCHAR2);
  720.  
  721.   --  (Re)Execute transactions that previously encountered conflicts. 
  722.   --  Exectuions stops when any error is encountered.  If some input is null,
  723.   --  then each transaciton is committed as it completes. If exactly one 
  724.   --  transaciton is specified, then the transactions is not commited.
  725.   --  Upon successful execution, transactions are removed for deferror, and if
  726.   --  there are no other references, entries are deleted from 
  727.   --  defcall and deftran.
  728.   --  Input Parameters:
  729.   --    deferrred_tran_db
  730.   --      node (global_name) originating or copying transaction that 
  731.   --      encounterd a errors. If null, then 
  732.   --      deferred_transaciton_id must be null and  all 
  733.   --      trnasactions from all destinations matching destinaiton 
  734.   --      (as specified) are re-executed.
  735.   --           
  736.   --    deferred_transaction_id
  737.   --      The identifier of the transation to be reexecuted.
  738.   --      If null then if all transactions in deferror matching 
  739.   --      deferred transaciton id and destination (as specified) 
  740.   --      are re-executed.
  741.   --    destination
  742.   --      dblink that transaction was originaly destined to.
  743.   --  Exceptions
  744.   --    Raises the last exception encountered before execution 
  745.   --    stops because of an exception.
  746.   ----------------
  747.  
  748.   PROCEDURE delete_tran(deferred_tran_id IN VARCHAR2,
  749.                         deferred_tran_db IN VARCHAR2,
  750.                         destination      IN VARCHAR2);
  751.   --  Delete transactions from  queues. Deletes deftrandest (and defcalldest
  752.   --  entries if appropriate.  If there are not other references,
  753.   --  deftran and defcall entries are deleted.
  754.   --  Input Parameters:
  755.   --    destination
  756.   --      dblink for which transaction(s) are to be removed from queues.
  757.   --      If null, the transaction specified by the other parameters are 
  758.   --      deleted from queues for all destinations.
  759.   --    deferred_tran_id
  760.   --      The identifier of the transation to be deleted
  761.   --      If null then all transactions matching destination and 
  762.   --      deferred_tran_db are deleted.
  763.   --    deferred_tran_db
  764.   --      The identifier of the origin/copying node for the transaction to be
  765.   --      deleted. If null then all transactiosn matching destination and 
  766.   --      deferred_tran_id are deleted.
  767.   --  Exceptions
  768.   --    tid and/or node not found.
  769.   ---------------
  770.   PROCEDURE delete_error(deferred_tran_id IN VARCHAR2,
  771.                          deferred_tran_db IN VARCHAR2,
  772.                          destination      IN VARCHAR2);
  773.  
  774.   --  Delete transactions from  defferror table. If there are 
  775.   --  not other references,
  776.   --  deftran and defcall entries are deleted.
  777.   --  Input Parameters:
  778.   --    destination
  779.   --      destinatoin for which transaction(s) are to be removed from 
  780.   --      deferror.
  781.   --      If null, the transaction specified by the other parameters are 
  782.   --      deleted from deferror for all destinations.
  783.   --    deferred_tran_id
  784.   --      The identifier of the transation to be deleted
  785.   --      If null then all transactions matching destination and 
  786.   --      deferred_tran_db are deleted.
  787.   --    deferred_tran_db
  788.   --      The identifier of the origin/copying node for the transaction to be
  789.   --      deleted. If null then all transaction matching destination and 
  790.   --      deferred_tran_id are deleted.
  791.   --  Exceptions
  792.   --    tid and/or node not found.
  793.   ---------------
  794.  
  795.   PROCEDURE copy(deferred_tran_id  IN VARCHAR2,
  796.                  deferred_tran_db  IN VARCHAR2,
  797.                  destination_list  IN dbms_defer.node_list_t,
  798.                  destination_count IN BINARY_INTEGER);
  799.   --  Copy as deferred transaciton assign it and new 
  800.   --  deferre_tranid , deferred__tran_db, 
  801.   -- executions_order, setting destination_list to 'D'
  802.   --  and retaining the other fields from the stource 
  803.   -- transaction).  The new transacitons has destitntions as 
  804.   -- specifies by destination_list and destination_count.
  805.   --    destination_node
  806.   --      the Origin_
  807.   --      Case  insesitive comparisons used.
  808.   --    tid
  809.   --      The identifier of the transation to be added to the node's queue.
  810.   --  Exceptions
  811.   --    tid  not found.
  812.   ---------------
  813.   PROCEDURE create_error(deferred_tran_id  IN VARCHAR2,
  814.                          deferred_tran_db  IN VARCHAR2,
  815.                          destination       IN VARCHAR2,
  816.                          call              IN NUMBER,
  817.                          error_number      IN NUMBER,
  818.                          error_message     IN VARCHAR2);
  819.                        
  820.   --  Create deferror table record for a transaction at 
  821.   --  some remote node. Delete deftrandest (and defcalldest, 
  822.   --  if appropriate) entries for transaction at the
  823.   --  node executing create_error. If there are not other
  824.   --  references, delete deftran and defcall entries.
  825.   --  Input Parameters:
  826.   --    destiation
  827.   --      dblink to node at which to create deferror table 
  828.   --      entry.
  829.   --    deferred_tran_id
  830.   --      The identifier of the transation.
  831.   --    deferred_tran_db 
  832.   --      databse idetifier component of the transciton.
  833.   --    call 
  834.   --      The identifier of the conflicitng call.  If not null should be
  835.   --      a call within the transaction
  836.   --    error_number
  837.   --      Error number for conflicts table record.
  838.   --    error_message
  839.   --      Error message for conflicts table record.
  840.   --      Truncated to 200 characters.
  841.   --
  842.   --  Exceptions
  843.   --------------
  844.   PROCEDURE schedule_execution(dblink         IN VARCHAR2,
  845.                                interval       IN VARCHAR2,
  846.                                next_date      IN DATE,
  847.                                reset          IN BOOLEAN default FALSE,
  848.                                stop_on_error  IN BOOLEAN := NULL,
  849.                                transaction_count IN BINARY_INTEGER := NULL,
  850.                                execution_seconds IN BINARY_INTEGER := NULL,
  851.                            execute_as_user   IN BOOLEAN := NULL,
  852.                                delay_seconds     IN NATURAL := NULL,
  853.                                batch_size        IN NATURAL := NULL);
  854.   -- Insert or update a defschedule entry and signal the background process.
  855.   -- this procedure does a commit;
  856.   -- Input Parameters:
  857.   --   dblink
  858.   --     Queue name to schedule execution for;
  859.   --   interval
  860.   --     If non-null then DefSchedule.interval for dblink is set to this 
  861.   --     value. If null and the DefSchedule entry for dblink exists, 
  862.   --     the value of DefSchedule.interval is not modified. If 
  863.   --     null and the DefSchedule entry 
  864.   --     for dblink does not exist, then the DefSchedule entry for 
  865.   --     dblink is created with a null interval value.
  866.   --   next_date
  867.   --     If non-null then DefSchedule.next_date for dblink is set to this 
  868.   --     value. If null and the DefSchedule entry for dblink exists, the value
  869.   --     of DefSchedule.next_date is not modified. If null and 
  870.   --     the DefSchedule entry 
  871.   --     for dblink does not exist, then the DefSchedule entry 
  872.   --     for dblink is created with a null next_date value.
  873.   --   reset
  874.   --     If TRUE then last_txn_count, last_error, and last_msg are nulled.
  875.   --    stop_on_error
  876.   --    transaction_count
  877.   --    execution_seconds
  878.   --    execute_as_user
  879.   --    delay_seconds
  880.   --    batch_size
  881.   --      If non-null, these parameters are passed to the dbms_defer_sys.execute
  882.   --      call that is scheduled for execution by this call.
  883.   ---------
  884.   PROCEDURE unschedule_execution(dblink         IN VARCHAR2);
  885.   --  Delete a defschedule entry. Signal to background process to stop 
  886.   --  servicing this queue.
  887.   -- Input Parameters:
  888.   --   dblink
  889.   --     Queue name to stop automatic execution of.
  890.   -- Exceptions:
  891.   --   NO_DATA_FOUND
  892.   --     no entry for dbling in DefSchedule.
  893. END dbms_defer_sys;
  894. /
  895. DROP PUBLIC SYNONYM dbms_defer_sys;
  896. CREATE PUBLIC SYNONYM dbms_defer_sys FOR dbms_defer_sys;
  897. GRANT EXECUTE ON dbms_defer_sys TO DBA; 
  898.  
  899.